﻿using System.Configuration;
using System.Collections.Generic;
using System;

namespace IGolovkine.ShoutCastRipper.Service.Configuration
{
    public class StreamTitleFilterElementCollection : ConfigurationElementCollection, IEnumerable<string>
    {
        private const string StreamTitleFilter = "streamTitleFilter";
        public StreamTitleFilterElementCollection()
        {
            this.AddElementName = StreamTitleFilter;
        }

        public StreamTitleFilterElement this[int index]
        {
            get { return (StreamTitleFilterElement) base.BaseGet(index); }
        }
        
        protected override ConfigurationElement CreateNewElement()
        {
            return new StreamTitleFilterElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((StreamTitleFilterElement) element).Regex;
        }

        public new IEnumerator<string> GetEnumerator()
        {
            for (int i = 0; i < this.Count; i++)
            {
                yield return this[i].Regex;
            }
        }
    }
}
